let Mock =require("mockjs")
// let data = [
//     {id:0,name:"张三",text:"法外狂徒"},
//     {id:1,name:"小新",text:"装傻的男人"},
//     {id:2,name:"胡图图",text:"是真的傻"},
//     {id:3,name:"柯南",text:"真相只有一个"},
//     {id:4,name:"乔巴",text:"是特殊时期的应急粮食"},
//     {id:5,name:"山治",text:"毕生梦想隐身果实"},
//     {id:6,name:"弗兰奇",text:"最变态的变态"},
//     {id:7,name:"罗宾",text:"收齐被掩盖的历史正文"},
//     {id:8,name:"布鲁克",text:"可以看看你的胖次吗"},
//     {id:9,name:"甚平",text:"鱼人空手道"},

// ]
let data = {
    user: [
        {id:0,name:"用户1",text:"我是用户1"},
        {id:1,name:"用户2",text:"我是用户2"},
        {id:2,name:"用户3",text:"我是用户3"},
        {id:3,name:"用户4",text:"我是用户4"},
        {id:4,name:"用户5",text:"我是用户5"},
        {id:5,name:"用户6",text:"我是用户6"},
        {id:6,name:"用户7",text:"我是用户7"},
        {id:7,name:"用户8",text:"我是用户8"},
        {id:8,name:"用户9",text:"我是用户9"},
        {id:9,name:"用户10",text:"我是用户10"},
    
    ],
    food:[
        {id:0,name:"橘子",text:"黄黄的"},
        {id:1,name:"杨桃",text:"像个五角星"},
        {id:2,name:"食品3",text:"食品3无添加剂"},
        {id:3,name:"食品4",text:"食品4无添加剂"},
        {id:4,name:"食品5",text:"食品5无添加剂"},
        {id:5,name:"食品6",text:"食品6无添加剂"},
        {id:6,name:"食品7",text:"食品7无添加剂"},
    ]
}
// 获取数据
Mock.mock("/api/homeuser","get",function(config){
    console.log(config)
    return data.user
})
// 修改数据
Mock.mock(/\/api\/homeuser\/edit\/\d/,"put",function(config){
    console.log(config)
    let arr=config.url.split("/")
    let id = arr.pop()
    let canshu=config.body 
    canshu =JSON.parse(canshu)
    data.user[id].name=canshu.name
    data.user[id].text=canshu.text
    return data
})
// 删除数据
Mock.mock(/\/api\/homeuser\/\d/,"delete",function(config){
    console.log(config.url)
    let arr= config.url.split("/")
    let id= arr.pop()
    data.user.splice(id,1)
    data.user=data.user.map(function(item,index){
        return {
            id:index,
            name:item.name,
            text:item.text
        }
    })
    return data
})